// Decal Classes.
// ==============

class pp_decal {
  int x, y, origin, xOffset, yOffset, depth, gid, objWidth, objHeight;
  int objFrames, waitFrames, currentFrame, currentWait;  // Animation variables.
  boolean isTile;
  String sprite;
  
  pp_decal(int PosX, int PosY, int Depth, int GID) { this(PosX, PosY, Depth, GID, 0, true, null); }
  pp_decal(int PosX, int PosY, int Depth, int Origin, String Sprite) { this(PosX, PosY, Depth, 0, Origin, false, Sprite); }
  pp_decal(int PosX, int PosY, int Depth, int GID, int Origin, boolean IsTile, String Sprite) {
    
    // Set parameters.
    x = PosX;
    y = PosY;
    depth = Depth;
    gid = GID;
    origin = Origin;    
    isTile = IsTile;
    sprite = Sprite;
    
    // If it's a sprite, set additional parameters.
    if (!isTile) {
      pp_sprite pix = spr.get(sprite);
      objWidth = pix.pixWidth;
      objHeight = pix.sprite.height;
      objFrames = pix.pixFrames;
      waitFrames = pix.waitFrames;
      
      if (origin != 0) {
        xOffset = pp_getXOffset(origin, objWidth);
        yOffset = pp_getYOffset(origin, objHeight);
      }
    }
  }
  
  void animate() {
    if (!isTile) {
      // Update frames according to FPS.
      if (currentWait < waitFrames) {
        currentWait++;
      } else {
        currentWait = 0;
        if (currentFrame < objFrames) {
          currentFrame++;
        } else {
          currentFrame = 0;
        }
      }
    }
  }
  
  void update() {
    if (isTile) {
      pp_drawTileDepth (x - pp_currentLevel.tileWidth, y - pp_currentLevel.tileHeight, depth, gid);
    } else {
      pp_drawSprite (x - xOffset, y - yOffset, depth, currentFrame, sprite);
    }
  }
}

// Decal Functions.
// ================

void pp_updateDecals() {
  for (pp_decal decal : pp_decals) {
    decal.animate();
    decal.update();
  }
}

void pp_drawTileDepth (int x, int y, int depth, int gid) {
  depthBuffer.append(nf(depth,4) + "1" + str(pp_signToInt(x)) + nf(abs(x),4) + str(pp_signToInt(y)) + nf(abs(y),4) + nf(gid,4));
}
